from fastapi import FastAPI
from redis import Redis
from rq import Queue
from worker import send_captcha
app = FastAPI()
redis_conn = Redis(host='myproj_redis', port=6379, db=0)
q = Queue('my_queue', connection=redis_conn)
# Request body classes


@app.get('/hello')
def hello():
    """Test endpoint"""
    return {'hello': 'world'}

@app.post('/send_captcha/{phone_number}', status_code=201)
def addTask(phone_number: str):
    """
    Adds tasks to worker queue. 
    Expects body as dictionary matching the Group class.

    """
    job = q.enqueue(send_captcha, phone_number)

    return {'job': "tasks add done."}
